﻿/**
 * ...
 * @author wangjun
 */
class cn.eminia.A2.utils.uString 
{
	
	public function uString() 
	{
		
	}
	

	public static function getCharLength(text_value:String):Number {
		var _lengths:Number = 0;//字符长度
		for(var _bai=0; _bai<text_value.length;_bai++){
			var ls_text = text_value.charAt(_bai);
			var _n = ls_text.charCodeAt(0)>255?2:1;
			_lengths += _n;
		}	
		return _lengths; 
	}
	public static function parseFFO(str:String, obj:Object) {
		var obj = (obj == null || obj == undefined) ? {} : obj;
		var arr = str.split(",");
		for (var i = 0; i<arr.length; i++) {
			var oo = arr[i];
			var ss = oo.split(":");
			obj[ss[0]] = toTypeFF(ss[1]);
		}
		return obj;
	}
	public static function chk(scope, id) {
		if (scope.constructor != MovieClip) {
			throw new Error('!! 错，该函数用代理 -> '+id);
		}
	}
	public static function toTypeFF(a) {
		if (isNaN(a)) {
			return (a);
		} else {
			return Number(a);
		}
	}
	public static function parseFFA(str:String) {
		var arr = str.split(",");
		return arr;
	}
	public static function all0(a) {
		for (var i in a) {
			a._visible = false;
		}
	}
	public static function all1(a) {
		for (var i in a) {
			a._visible = true;
		}
	}
	public static function replace(a:String, b:String, c:String):String {
		if (b == '\r' && c == null) {
			if (a.indexOf('\r') == -1) {
				return a;
			} else {
				var arr = a.split('\r');
				var str:String = '';
				for (var i = 0; i<arr.length; i++) {
					str += arr[i]+newline;
				}
				return str;
			}
		} else {
			trace('-> '+a.indexOf(b));
			if (a.indexOf(b) == -1) {
				return a;
			} else {
				var arr = a.split(b);
				var str:String = '';
				for (var i = 0; i<arr.length; i++) {
					str += arr[i]+c;
				}
				return str;
			}
		}
	}
	public static function compareArray(a, b):Boolean {
		if (a.length != b.length) {
			return false;
		}
		for (var i = 0; i<a.length; i++) {
			if (a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
	public static function getType(a) {
		if (a.constructor == Number) {
			return 'num';
		} else if (a.constructor == String) {
			return 'str';
		} else if (typeof (a) == 'object') {
			if (a.text == undefined) {
				return 'arr';
			} else {
				return 'tf';
			}
		} else if (a.constructor == MovieClip ) {
			if (a.style == 'mix') {
				return 'mix';
			}
			return 'mc';
		}
	}
	public static function traceObj(obj) {
		trace('!! '+obj);
		for (var i in obj) {
			trace('!! '+i+' -> '+obj[i]);
		}
	}
	public static function orderBy(type, scope):Array {
		var arr:Array = [];
		if (type == '|') {
			for (var i in scope) {
				//if (scope[i] instanceof MovieClip) {
				if (scope[i].constructor == MovieClip) {
					arr.push({mc:scope[i], pos:Math.floor(scope[i]._y)});
				}
			}
		} else {
			for (var i in scope) {
				if (scope[i] instanceof MovieClip) {
					arr.push({mc:scope[i], pos:Math.floor(scope[i]._x)});
				}
			}
		}
		arr.sortOn('pos',Array.NUMERIC);
		//arr.reverse();
		//
		var arr2 = [];
		for (var i = 0; i<arr.length; i++) {
			//trace(arr[i].mc._name+' - '+arr[i].pos)
			arr2.push(arr[i].mc);
		}
		return arr2;
	}
	
}